package com.flexcloudsdk.xmpp;

import java.util.logging.Logger;
import com.google.appengine.api.xmpp.XMPPService;
import com.google.appengine.api.xmpp.XMPPServiceFactory;
import com.google.appengine.api.xmpp.JID;
import com.google.appengine.api.xmpp.Message;
import com.google.appengine.api.xmpp.Presence;
import com.google.appengine.api.xmpp.SendResponse;
import com.google.appengine.api.xmpp.PresenceShow;
import com.google.appengine.api.xmpp.PresenceType;

public class CloudXMPPService {
	private static final Logger log = Logger.getLogger(CloudXMPPService.class.getName());

	XMPPService service;
	public CloudXMPPService() {
		log.info("CloudXMPPService has been created by BlazeDS");
		service = XMPPServiceFactory.getXMPPService();
	}

	public Presence getPresence(JID jabberId) {
		Presence present = null;
		try {
			present = service.getPresence(jabberId);
		} catch (IllegalArgumentException exception) {
			log.severe(exception.getMessage());
		}
		return present;
	}
	
	public Presence getPresence(JID jabberId, JID fromJid) {
		Presence present = null;
		try {
			present = service.getPresence(jabberId, fromJid);
		} catch (IllegalArgumentException exception) {
			log.severe(exception.getMessage());
		}
		return present;
	}
	
	public void sendInvitation(JID jabberId) {
		try {
			service.sendInvitation(jabberId);
		} catch (IllegalArgumentException exception) {
			log.severe(exception.getMessage());
		}
	}
	
	public void sendInvitaion(JID jabberId, JID fromJid) {
		try {
			service.sendInvitation(jabberId, fromJid);
		} catch (IllegalArgumentException exception) {
			log.severe(exception.getMessage());
		}
	}
	
	public SendResponse sendMessage(Message message) {
		SendResponse response = null;
		try {
		 response = service.sendMessage(message);
		} catch (IllegalArgumentException exception) {
			log.severe(exception.getMessage());
		}
		return response;
	}
	
	public void sendPresence(JID jabberId, PresenceType type, PresenceShow show, String status) {
		try {
			service.sendPresence(jabberId, type, show, status);
		} catch (IllegalArgumentException exception) {
			log.severe(exception.getMessage());
		}
	}
	
	public void sendPresence(JID jabberId, PresenceType type, PresenceShow show, String status, JID fromJid) {
		try {
			service.sendPresence(jabberId, type, show, status, fromJid);
		} catch (IllegalArgumentException exception) {
			log.severe(exception.getMessage());
		}
	}
	
}
